/**
 *  Filename: WiFiReading.java (in org.repin.base.core.measure)
 *  This file is part of the Redpin project.
 * 
 *  Redpin is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published
 *  by the Free Software Foundation, either version 3 of the License, or
 *  any later version.
 *
 *  Redpin is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Redpin. If not, see <http://www.gnu.org/licenses/>.
 *
 *  (c) Copyright ETH Zurich, Pascal Brogle, Philipp Bolliger, 2010, ALL RIGHTS RESERVED.
 * 
 *  www.redpin.org
 */
package ch.simplix.android.net.discoverer.wifi;


/**
 * Describes a WiFi reading
 * 
 * @author Philipp Bolliger (philipp@bolliger.name)
 * @author Simon Tobler (simon.p.tobler@gmx.ch)
 * @author Pascal Brogle (broglep@student.ethz.ch)
 * @author reto Koenig
 * @version 0.3
 */
public class WiFiReading {

	

	/** The unique id of the AP. This is the same thing as the AP's MAC address * */
	protected String bssid = "";

	/** The human readable network address (e.g. 'default' or 'eth') * */
	protected String ssid = "";

	/** The observed signal strength * */
	protected int rssi = 0;

	/** Denotes whether encryption in enabled for the AP or not * */
	protected boolean encryptionEnabled = false;

	/** Denotes whether the AP in in infrastructure or peer-to-peer mode * */
	protected boolean isInfrastructure = true;
	
	/** Denotes the frequency the signal signal is broadcasted over */
	protected int frequency = 0 ;

	/* **************** Getter and Setter Methods **************** */

	/**
	 * @return the bssid
	 */
	public String getBssid() {
		return bssid;
	}

	/**
	 * @param bssid
	 *            the bssid to set
	 */
	public void setBssid(String bssid) {
		this.bssid = bssid;
	}

	/**
	 * @return the ssid
	 */
	public String getSsid() {
		return ssid;
	}

	/**
	 * @param ssid
	 *            the ssid to set
	 */
	public void setSsid(String ssid) {
		this.ssid = ssid;
	}

	/**
	 * @return the rssi
	 */
	public int getRssi() {
		return rssi;
	}

	/**
	 * @param rssi
	 *            the rssi to set
	 */
	public void setRssi(int rssi) {
		this.rssi = rssi;
	}

	/**
	 * @return the encryption state
	 */
	public boolean isEncryptionEnabled() {
		return encryptionEnabled;
	}

	/**
	 * @param encryptionEnabled
	 *            the wepEnabled to set
	 */
	public void setEncryptionEnabled(boolean encryptionEnabled) {
		this.encryptionEnabled = encryptionEnabled;
	}

	/**
	 * @return the isInfrastructure
	 */
	public boolean isInfrastructure() {
		return isInfrastructure;
	}

	/**
	 * @param isInfrastructure
	 *            the isInfrastructure to set
	 */
	public void setInfrastructure(boolean isInfrastructure) {
		this.isInfrastructure = isInfrastructure;
	}

	public int getFrequency() {
		return frequency;
	}
	public void setFrequency(int frequency) {
		this.frequency = frequency;
	}
	
	

	public int getNormalizedSignalStrength() {
		// TODO test and rewrite (taken from placelab)
		// return an int 0-100 depending on the signal strength, or -1 if
		// unsupported
		// linear heuristic based on histogram of logs at IRS
		// -45 => 100, -60 => 67, -75 => 33, -90 => 0
		// int retval = (100*(90 + rssi)) / 45;

		// JWS changed this since supporting particlefilters is easier this way
		// will affect the colouring on XMapDemo - more yellows and less
		// reds/greens
		int retval = rssi + 100;
		if (retval < 0)
			retval = 0;
		if (retval > 100)
			retval = 100;
		return retval;
	}

	public String getHumanReadableName() {
		return ssid + " (" + bssid + ")";
	}

	@Override
	public String toString() {
		return "BSSID=" + bssid + "|SSID=" + ssid + "|RSSI =" + rssi + "|GHz="+ (frequency/1000.0)+"|Encryption=" + encryptionEnabled + "|INFR =" + isInfrastructure;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((bssid == null) ? 0 : bssid.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		WiFiReading other = (WiFiReading) obj;
		if (bssid == null) {
			if (other.bssid != null)
				return false;
		} else if (!bssid.equals(other.bssid))
			return false;
		return true;
	}

	
}
